package cn.tedu.ou;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

@Component
public class GuanYu {
    private String name="关二爷";
    // 关羽类中的依赖关系由之前的具体类型修改为抽象类型,实现解耦
    // 运行时会自动从Spring容器中搜索Weapon类型的对象来实现依赖注入
    // 更换依赖对象时,只需要更换指定的注入对象即可
    @Autowired
    @Qualifier("snakeLance")
    private Weapon weapon;
    @Autowired
    @Qualifier("redRabbit")
    private Mount mount;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Weapon getWeapon() {
        return weapon;
    }

    public void setWeapon(Weapon weapon) {
        this.weapon = weapon;
    }

    public void fight(){
        System.out.println(
                name+"骑着"+mount.getName()+
                "使用"+weapon.getName()+"战斗");
    }
}
